/*
* @Author: dengjiayao
* @Date:   2017-08-29 14:08:25
* @Last Modified by:   dengjiayao
* @Last Modified time: 2017-08-30 17:15:51
*/
import Pages from '../../../component/pages/pages.vue'
import { showMsg, getSelectedBetaList, deleteSelectedBeta } from '../../../vuex/action'

export default {
  name: 'editor-chosen-list',
  components: {
    'vue-pages': Pages
  },
  data() {
    return {
      list: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      }
    }
  },
  vuex: {
    getters: {
      fresh: state => state.portfolioListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xGetList: getSelectedBetaList,
      xDelete: deleteSelectedBeta
    }
  },
  created() {
    this.getList({})
  },
  methods: {
    getList({start=this.pages.start, limit=this.pages.limit}) {
      this.xGetList({
        start: start,
        limit: limit
      })
        .then((data) => {
          this.list = data.list
          this.pages.totalPages = Math.ceil(data.count / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    deleteItem(id) {
      this.xDelete({
        id: id
      })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    swapMarket(market) {
      this.filter.market = market
      this.getList({})
    }
  },
  watch: {
    fresh(val) {
      if (val) {
        this.getList({})
      }
    }
  }
}
